package com.neu.wms.controller;

import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.neu.wms.dto.UserDto;
import com.neu.wms.service.SupplierService;
import com.neu.wms.util.ResultVo;
import com.neu.wms.util.entity.SysUser;
import com.neu.wms.util.entity.WmsSupplier;
import com.neu.wms.vo.UserVo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("/suppliers")
public class SupplierController {
        @Autowired
        private SupplierService supplierService;

    @PostMapping("queryAll")
    public ResultVo queryAll(){
        List<WmsSupplier> wmsSupplierList = supplierService.selectAll();
        return ResultVo.ok().data("list",wmsSupplierList);
    }

    @DeleteMapping("{id}")
    public ResultVo delete(@PathVariable("id") Long id){
        int i =supplierService.deleteByPrimaryKey(id);
        if (i > 0) {
            return ResultVo.ok("删除成功");
        } else {
            return ResultVo.error("删除失败");
        }
    }

    @GetMapping("{id}")
    public ResultVo queryById(@PathVariable("id") Long id){
        WmsSupplier supplier = supplierService.selectByPrimaryKey(id);
        return ResultVo.ok().data("supplier",supplier);
    }

    @PutMapping("")
    public ResultVo update(@RequestBody WmsSupplier supplier){
        int i = supplierService.updateByPrimaryKeySelective(supplier);
        if (i>0) {
            return ResultVo.ok("修改成功");
        }else {
            return ResultVo.error("修改失败");
        }
    }
    @PostMapping("")
    public ResultVo add(@RequestBody WmsSupplier supplier){
        int i = supplierService.insertSelective(supplier);
        if (i>0) {
            return ResultVo.ok("添加成功");
        }else {
            return ResultVo.error("添加失败");
        }
    }
}
